#! /bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2000,2002 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
#
# ===== RedHat/Turbo chkconfig =====
# chkconfig: 2345 33 67
# description: Resource Monitoring and Control services
#
# ===== SuSE insserv =====
### BEGIN INIT INFO
# Provides:       ctrmc
# Required-Start:
# Required-Stop:
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6
# Description: Resource Monitoring and Control services
### END INIT INFO
#
#*===========================================================================*/
#*                                                                           */
#* Module Name:  rc_ctrmc                                                    */
#*                                                                           */
#* Description:                                                              */
#*      Script to start/stop the Resource Monitor & Control Daemon           */
#*      at bootup or when the runlevel changes.                              */
#*                                                                           */
#*===========================================================================*/
#*   @(#)34   1.3   src/rsct/rmc/mcdaemon/rc_ctrmc.sh, mcdaemon, rsct_rpyxh, rpyxht1f3 5/21/02 12:44:59 

# define function to start the ctrmc subsystem. Use initlog to log messages

start_ctrmc() {
	if [[ -x /sbin/initlog ]]
	then
		initlog $I_ARGS -c "rmcctrl -s"
		rc=$?
		if [[ $rc -eq 0 ]]
		then
			initlog $I_ARGS -n rc_ctrmc -s "ctrmc startup" -e 1
			# touch lock file /var/lock/subsys/ctrmc in rmcctrl -s
			#touch /var/lock/subsys/ctrmc
		else
			initlog $I_ARGS -n rc_ctrmc -s "ctrmc startup" -e 2
		fi
	else
		rmcctrl -s
		rc=$?
	fi
	return $rc
}

# define function to stop the ctrmc subsystem. Use initlog to log messages

stop_ctrmc() {
	if [[ -x /sbin/initlog ]]
	then
		initlog $I_ARGS -c "rmcctrl -k"
		rc=$?
		if [[ $rc -eq 0 ]]
		then
			initlog $I_ARGS -n rc_ctrmc -s "ctrmc shutdown" -e 1
			# remove lock file /var/lock/subsys/ctrmc in rmcctrl -k
			#rm -f /var/lock/subsys/ctrmc
		else
			initlog $I_ARGS -n rc_ctrmc -s "ctrmc shutdown" -e 2
		fi
	else
		rmcctrl -k
		rc=$?
	fi
	return $rc
}

# Set path to known value
PATH=/usr/sbin/rsct/bin:/usr/bin:/usr/sbin:/bin:/sbin
export PATH

if [[ "$BOOTUP" != "verbose" ]]
then
	I_ARGS="-q"
else
	I_ARGS=
fi

# Invoke the logic specified by the command argument

case "$1" in
	start)
		start_ctrmc
		rc=$?
		;;

	stop)
		stop_ctrmc
		rc=$?
		;;

	status)
		lssrc -s ctrmc
		rc=$?
		;;

	restart|reload)
		stop_ctrmc
		start_ctrmc
		rc=$?
		;;

	*)
		echo "Usage: rc_ctrmc {start|stop|status|restart}"
		exit 1
		;;
esac

exit $rc

